import requests from "@/utils/request";

const state = {
  swipterList: [],
  waterPullList: [],
  page: 1,
};
const mutations = {
  GETSWIPTER(state, list) {
    state.swipterList = list;
  },
  GETWATERPULL(state, list) {
    list.forEach((item) => state.waterPullList.push(item));
    state.page++;
  },
};
const actions = {
  // 获取轮播图数据
  async getSwipter({ state, commit, dispatch }) {
    try {
      let result = await requests("/wy/topic/v1/know/navWap.json");

      commit("GETSWIPTER", result.data.navList);
    } catch (error) {
      console.log("获取轮播图数据失败");
    }
  },
  // 获取瀑布流数据
  async getWaterPull({ state, commit, dispatch }) {
    try {
      let result = await requests({
        url: "/wy/topic/v1/find/recAuto.json",
        method: "get",
        params: { page: state.page, size: 8 },
      });
      // let result = await requests("/api/topic/v1/find/recAuto.json?page=2&size=8");

      commit("GETWATERPULL", result.data.result);
    } catch (error) {
      console.log("获取瀑布流数据失败");
    }
  },
};
const getters = {};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
